package model

import "gorm.io/gorm"

type Like struct {
	gorm.Model
	UserId int `gorm:"type:int" json:"userId"`
	PostId int `gorm:"type:int" json:"postId"`
	Count  int `gorm:"type:int;default:0" json:"count"`
}

func (l *Like) IsLike(db *gorm.DB, userId int, postId int) error {
	err := db.Where("user_id = ? and post_id = ?", userId, postId).First(&l).Error
	return err
}

func (l *Like) AddLike(db *gorm.DB) error {
	return db.Create(&l).Error
}
